package com.wzh.yebServe.controller;

import com.wzh.yebServe.pojo.Menu;
import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.pojo.Role;
import com.wzh.yebServe.service.IMenuRoleService;
import com.wzh.yebServe.service.IMenuService;
import com.wzh.yebServe.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/16 15:37
 * @Description:权限组
 */
@Api(value = "PermissController 角色管理接口")
@RestController
@RequestMapping("/system/basic/permiss")
public class PermissController {
    @Autowired
    private IRoleService iRoleService;

    @Autowired
    private IMenuService iMenuService;

    @Autowired
    private IMenuRoleService iMenuRoleService;


    @ApiOperation(value = "查询所有的角色")
    @GetMapping("/")
    public List<Role> getAllRoles(){
        return iRoleService.getAllRoles();
    }


    @ApiOperation(value = "添加一个角色")
    @PostMapping("/role")
    public ResultBean addRole(@RequestBody Role role){
        return iRoleService.addRole(role);
    }

//
//    @ApiOperation(value = "修改角色信息")
//    @PutMapping("/")
//    public ResultBean updateRole(@RequestBody Role role){
//        return iRoleService.updateRole(role);
//
//    }


    @ApiOperation(value = "根据id删除角色")
    @DeleteMapping("/role/{rid}")
    public ResultBean deleteRole(@PathVariable Integer rid){
       return iRoleService.deleteRole(rid);

    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping("/")
    public ResultBean deleteRoleByids(Integer [] ids){
        return iRoleService.deleteRoleByids(ids);
    }


    @ApiOperation(value = "查询所有的菜单")
    @GetMapping("/menus")
    public List<Menu> getAllMenu(){
        return iMenuService.getAllMenu();
    }


    @ApiOperation(value = "根据角色id查询菜单id")
    @GetMapping("/mid/{rid}")
    public List<Integer> getMidByRid(@PathVariable Integer rid){
        return iMenuRoleService.getMidByRid(rid);
    }



    @ApiOperation(value = "更新角色菜单")
    @PutMapping("/")
    public ResultBean updateMenuRole(Integer rid,Integer[] mids){
        return iMenuRoleService.updateMenuRole(rid,mids);
    }


}
